﻿
@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Create</h2>
<link href="/Content/themes/base/jquery-ui.css" rel="stylesheet" />

<div id="main">
    <div class="demo statemachine-demo" id="statemachine-demo">
        <div class="WorkflowStart" id="StartWorkflow">Start  <div class="ep"></div></div>
    </div>

</div>
<div style="display:none">
    <div class="popupForm">
        <div class="popup"></div>
        <div>
            <ul>
                <li><input id="popform_save" type="button" name="button_save" value="Save" /> </li>
                <li><input type="button" name="button_cancel" value="Cancel" /> </li>
            </ul>
        </div>
    </div>
</div>
<div id="toolbar">
    <input type="button" name="Task" value="Task" onclick="AddTask();" />
    <input type="button" name="Decision" value="Decision" onclick="new Activity('#statemachine-demo').AddDecision();" />
    <input type="button" name="Export" value="Export" onclick="OpenPublishDailog();" />

    <input type="submit"  name="Save" value=" " />
</div>

<div style="display:none">
    <div id="publishDailog">
        <form action="@Url.Action("Create","Workflow")" method="post" sold="publish">
        <ul>
            <li>
                <label for="Title">Workflow Title</label>
                <input type="text" name="Title" value=" " />
                <br />
            </li>
        </ul>
            <ul>
                <li>
                    <label for="Xml">Workflow Xml</label>
                    <input type="text" name="Xml" value="" />
                    <br />
                </li>
            </ul>
            <ul>
                <li>
                    <input type="button"    name="Publish" value="Publish" onclick="PublishWorkflow();" />
                    <input type="button" name="CancelPublish" value="CancelPublish" onclick="CancelPublish();" />
                </li>
            </ul>

        </form>
    </div>

</div>

<script>
    var NextActivityId = 1;
    var ServiceUrl = "http://localhost:19659/WorkflowClient.svc";
    function GetNextActivityId() {
        var activityid = "Activity" + NextActivityId;
        NextActivityId++;
        return activityid;
    }

    function AddTask() {
        new Activity("#statemachine-demo").AddTask();
    }
    
    function OpenPublishDailog() {
        var activity = new Activity();
        var xml = activity.export();
        
        $("input[name*='Xml']").val(xml);
        
        var publishPopup = $("#publishDailog");
        publishPopup.dialog({ modal: true, width: 500, height: 400, title: "Publish Workflow" });
        publishPopup.dialog('open');
    }
    function PublishWorkflow() {
        
        var $form =$("form[sold='publish']");
        var option =
            {
                url : $form.attr("action"),
                type : $form.attr("method"),
                cache: false,
                data: $form.serialize()
            };
        $.ajax(option).done(function (data) {
            if(data=="done")
            {
                current_dialog.dialog('close');
                alert("Record Updated.");
                location.reload();
            }
            else
                if(data!=null)
                    alert(data);
                else
                    alert('Error While updating Record');
        });
    
    }
    function CancelPublish() {
        var publishPopup = $("#publishDailog");
        publishDailog.dailog('close');
    }
</script>

<!-- DEP -->
<script src="/Scripts/jquery-2.0.3.min.js"></script>
<script src="/Scripts/jquery-ui-1.10.4.min.js"></script>/
<script src="/Scripts/lib/jquery.ui.touch-punch.min.js"></script>
<script src="/Scripts/jquery.ui-contextmenu.min.js"></script>/
<!-- /DEP -->

<!-- Models -->
<script src="/Scripts/workflow/models/WorkflowActivity.js"></script>
<script src="/Scripts/workflow/models/WorkflowConnection.js"></script>
<script src="/Scripts/workflow/models/WorkflowScript.js"></script>
<script src="/Scripts/workflow/UI/ActivityDailog.js"></script>
<!-- UI -->
<script src="/Scripts/workflow/UI/ActivityUi.js"></script>
<!-- for demo dropdown. not a jsplumb dependency -->
<!-- JS -->
<!-- support lib for bezier stuff -->
<script src="/Scripts/lib/jsBezier-0.6-min.js"></script>
<!-- jsplumb geom functions -->
<script src="/Scripts/lib/jsplumb-geom-0.1.js"></script>
<!-- jsplumb util -->
<script src="/Scripts/src/util.js"></script>
<!-- base DOM adapter -->
<script src="/Scripts/src/dom-adapter.js"></script>
<!-- main jsplumb engine -->
<script src="/Scripts/src/jsPlumb.js"></script>
<!-- endpoint -->
<script src="/Scripts/src/endpoint.js"></script>
<!-- connection -->
<script src="/Scripts/src/connection.js"></script>
<!-- anchors -->
<script src="/Scripts/src/anchors.js"></script>
<!-- connectors, endpoint and overlays  -->
<script src="/Scripts/src/defaults.js"></script>
<!-- bezier connectors -->
<script src="/Scripts/src/connectors-bezier.js"></script>
<!-- state machine connectors -->
<script src="/Scripts/src/connectors-statemachine.js"></script>
<!-- flowchart connectors -->
<script src="/Scripts/src/connectors-flowchart.js"></script>
<script src="/Scripts/src/connector-editors.js"></script>
<!-- SVG renderer -->
<script src="/Scripts/src/renderers-svg.js"></script>
<!-- canvas renderer -->
<script src="/Scripts/src/renderers-canvas.js"></script>
<!-- vml renderer -->
<script src="/Scripts/src/renderers-vml.js"></script>

<!-- jquery jsPlumb adapter -->
<script src="/Scripts/src/jquery.jsPlumb.js"></script>
<!-- /JS -->
<!--  demo code -->
<script src="/Scripts/demo-jquery.js"></script>
